/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Students {
    public static boolean insertStudent(Entity.Student std){
        try {
            String sql = "insert into tblStudents values(?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, std.get_StudentID());
            ps.setString(2, std.get_FullName());
            ps.setString(3, std.get_PhoneNum());
            ps.setString(4, std.get_MobileNum());
            ps.setString(5, std.get_Birthday());
            ps.setBoolean(6, std.is_Gender());
            ps.setString(7, std.get_Address());
            ps.setString(8, std.get_Email());
            ps.setString(9, std.get_IdentityCard());
            ps.setString(10, std.get_ClassID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Students.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateStudent(Entity.Student std){
        try {
            String sql = "update tblStudents set FullName=?, PhoneNum=?, MobileNum=?, Birthday=?, Gender=?, Address=?, Email=?, IdentityCard=?, ClassID=? where StudentID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, std.get_FullName());
            ps.setString(2, std.get_PhoneNum());
            ps.setString(3, std.get_MobileNum());
            ps.setString(4, std.get_Birthday());
            ps.setBoolean(5, std.is_Gender());
            ps.setString(6, std.get_Address());
            ps.setString(7, std.get_Email());
            ps.setString(8, std.get_IdentityCard());
            ps.setString(9, std.get_ClassID());
            ps.setString(10, std.get_StudentID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Students.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static void deleteStudent(String StudentID)
    {
        try {
            String sql = "delete from tblStudents where StudentID = '" + StudentID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Students.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
}
